// pages/main/choose_course/choose_course.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type_array:['通识一般选修课','英语课','心理选修课','体育课'],
    type_index:0,
    week_array:['星期一','星期二','星期三','星期四','星期五','星期六','星期日'],
    week_index:0,
    time_array:['1-2节','3-4节','3-5节','6-7节','6-8节','6-9节','8-9节','10-11节','10-12节'],
    time_index:0,
    allValue:''
  },
  formSubmit:function(e){
    this.setData({
      allValue:e.detail.value
    })
  },
  bindTypeChange:function(e){
    this.setData({
      type_index:e.detail.value
    })
  },
  bindTimeChange:function(e){
    this.setData({
      time_index:e.detail.value
    })
  },
  bindWeekChange:function(e){
    this.setData({
      week_index:e.detail.value
    })
  },

  next:function(e){
    wx.redirectTo({
      url: '/pages/main/choose_course/result_course/result_course'
    })
  },

  findClass: function(res) {
    var that=this;
    var data = res.detail.value;
    const db = wx.cloud.database()
    db.collection('class').get({
      success: (res) => {
        let classes =res.data;
        let n = 0;
        //console.log(classes)
        //console.log(data)
        for (let i = 0; i < classes.length; i++) {  //遍历数据库对象集合
          if(data.choose_class_name === classes[i].class_name &&
            that.data.time_array[data.choose_class_time_time] === classes[i].time &&
            that.data.week_array[data.choose_class_time_week] === classes[i].week &&
            that.data.type_array[data.choose_class_type] === classes[i].type)
          {
            console.log("succeed")
            n = 1;
            getApp().globalData.choose_class = classes[i]
            that.next()
          }
        }
        if (n == 0) {
          wx.showToast({
            title: '课程不存在！！',
            icon: 'loading',
            duration: 2500
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  return:function(){
    wx.navigateBack({
      delta:1
    })
  },
})